From 6d7ce094e4d1d429fe0c79d40d195f408691d568 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 29 May 2015 19:25:19 -0700 Subject: [PATCH] Optimize SourceId::cmp a bit --- src/cargo/core/source.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index 8a89c5546..7551161bc 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -245,13 +245,23 @@ impl PartialEq for SourceId { impl PartialOrd for SourceId { fn partial_cmp(&self, other: &SourceId) -> Option { - self.to_string().partial_cmp(&other.to_string()) + Some(self.cmp(other)) } } impl Ord for SourceId { fn cmp(&self, other: &SourceId) -> Ordering { - self.to_string().cmp(&other.to_string()) + match self.inner.kind.cmp(&other.inner.kind) { + Ordering::Equal => {} + ord => return ord, + } + if let Kind::Git(..) = self.inner.kind { + match self.inner.precise.cmp(&other.inner.precise) { + Ordering::Equal => {} + ord => return ord, + } + } + self.inner.url.to_string().cmp(&other.inner.url.to_string()) } } -- 2.30.2